<template>
  <div class="model-container">
    <div class="listName">资讯管理</div>

    <el-card shadow="never">
      <div slot="header" class="clearfix">
        <span>快捷搜索</span>
        <div class="btns-wrapper-right">
          <el-button v-if="!searchShow" icon="el-icon-arrow-down" @click="searchShow = true" />
          <el-button v-else icon="el-icon-arrow-up" @click="searchShow = false" />
        </div>
      </div>
      <el-collapse-transition>
        <div v-show="searchShow" class="cardbody">
          <el-form ref="seacherParam" :model="seacherParam">
            <el-row :gutter="10">
              <el-col :xl="5" :lg="6" :md="6" :sm="8">
                <el-col :xl="7" :lg="7" :md="8" :sm="8" class="input-name">关键字搜索</el-col>
                <el-col :xl="17" :lg="17" :md="16" :sm="16">
                  <el-form-item prop="newsContent">
                    <el-input v-model="seacherParam.newsContent" size="small" placeholder="请输入关键字" />
                  </el-form-item>
                </el-col>
              </el-col>
              <el-col :xl="5" :lg="6" :md="6" :sm="8" >
                <el-col :xl="7" :lg="7" :md="8" :sm="8" class="input-name">资讯类型</el-col>
                <el-col :xl="17" :lg="17" :md="16" :sm="16">
                  <el-form-item prop="newsType">
                    <el-select v-model="seacherParam.newsType" size="small" value="0" placeholder="请选择">
                      <el-option :value="0" label="文字"/>
                      <el-option :value="1" label="图文"/>
                      <el-option :value="2" label="视频"/>
                    </el-select>
                  </el-form-item>
                </el-col>
              </el-col>
              <el-col :xl="5" :lg="6" :md="6" :sm="8">
                <el-col :xl="7" :lg="7" :md="8" :sm="8" class="input-name">用户昵称</el-col>
                <el-col :xl="17" :lg="17" :md="16" :sm="16">
                  <el-form-item prop="nickName">
                    <el-input v-model="seacherParam.nickName" size="small" placeholder="请输入用户昵称" />
                  </el-form-item>
                </el-col>
              </el-col>
            </el-row>
            <div class="cardfooter">
              <el-button type="primary" size="mini" plain @click="seachFun">查询</el-button>
              <el-button type="warning" size="mini" plain @click="resetFun">重置</el-button>
            </div>
          </el-form>
        </div>
      </el-collapse-transition>
    </el-card>

    <el-card style="margin-top: 10px">
      <div slot="header" class="clearfix">
        <div class="btns-wrapper-left">
          <el-button type="primary" plain @click="add">新增</el-button>
        </div>
      </div>
      <div class="table-wrapper">
        <el-table v-loading="!dataOption" :stripe="true" :data="dataOption" border empty-text="暂无数据" status-icon @selection-change="changeFun">

          <el-table-column align="center" width="55" label="序号" type="index" />

          <el-table-column align="center" prop="newsContent" label="资讯内容" show-overflow-tooltip/>

          <el-table-column align="center" prop="fristFrameUrl" label="资讯封面图">
            <template slot-scope="scope">
              <img v-if="scope.row.newsType === 2" :src="scope.row.fristFrameUrl" width="50px" height="50px">
              <img v-else-if="scope.row.newsType === 1" :src="formatImageUrl(scope.row.otherUrl)" width="50px" height="50px">
            </template>
          </el-table-column>

          <el-table-column align="center" prop="name" label="类型">
            <template slot-scope="scope">{{ newsTypeFun(scope.row.newsType) }}</template>
          </el-table-column>

          <el-table-column v-if="getUser().sellerId === null" align="center" label="同步到">
            <template slot-scope="scope">
              <!--              <p class="comment" @click="sync(scope.row)">{{ scope.row.sellerName }}</p> -->
              <el-button v-if="scope.row.newsSource === 0" type="primary" size="mini" plain @click="sync(scope.row)">同步到商家</el-button>
              <el-button v-else-if="scope.row.newsSource === 1" type="primary" size="mini" plain @click="sync(scope.row)">同步到平台</el-button>
            </template>
          </el-table-column>

          <!--          <el-table-column align="center" label="评论">
            <template slot-scope="scope">
              <p class="comment" @click="check(scope.row)">{{ scope.row.commentNum }}</p>
            </template>
          </el-table-column> -->

          <el-table-column align="center" label="评论管理">
            <template slot-scope="scope">
              <el-button title="查看" type="primary" circle class="table-icon " icon="iconfont icon-chakan2" @click="check(scope.row)" />
            </template>
          </el-table-column>

          <el-table-column align="center" prop="createTime" label="创建时间" />

          <el-table-column align="center" prop="topDays" label="置顶天数" />

          <el-table-column align="center" prop="" label="状态">
            <template slot-scope="scope">
              <div v-if="scope.row.newsStatus === 1">已发布</div>
              <div v-else-if="scope.row.newsStatus === 2">下线</div>
            </template>
          </el-table-column>

          <el-table-column align="center" prop="remainderTop" label="剩余置顶天数" />

          <el-table-column align="center" prop="nickName" label="发布者" />

          <el-table-column align="center" label="操作" width="400px">
            <template slot-scope="scope">
              <el-button type="success" size="mini" plain @click="look(scope.row)">查看</el-button>
              <template v-if="(getUser().sellerId !== null && scope.row.newsSource !== 0 && getUser().memberId === scope.row.userId) || getUser().sellerId === null">
                <el-button type="primary" size="mini" plain @click="edit(scope.row)">修改</el-button>
                <el-button v-if="scope.row.isTop === 0" type="primary" size="mini" plain @click="top(scope.row)">热推置顶</el-button>
                <el-button v-else type="primary" size="mini" plain @click="top(scope.row)">取消置顶</el-button>
                <el-button type="danger" size="mini" plain @click="del(scope.row)">删除</el-button>
                <el-button v-if="scope.row.newsStatus === 2" type="warning" size="mini" plain @click="publish(scope.row)">发布</el-button>
                <el-button v-else-if="scope.row.newsStatus === 1" type="warning" size="mini" plain @click="publish(scope.row)">下线</el-button>
              </template>
            </template>
          </el-table-column>

        </el-table>

        <!--分页-->
        <el-pagination
          :current-page="pageNo"
          :page-sizes="[10, 20, 30]"
          :page-size="pageSize"
          :total="rowCount"
          background
          layout="total, sizes, prev, pager, next, jumper"
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange" />
      </div>
    </el-card>

    <!--弹框-->
    <el-dialog :title="dialogTitle" :visible.sync="dialogState" :before-close="handleClose" top="5vh" width="80%">
      <el-form ref="dialogBindData" :model="dialogBindData" :rules="rules" label-width="30%" status-icon class="demo-ruleForm">
        <div class="formBody">
          <el-form-item label="资讯类型" prop="newsType">
            <el-select v-model="dialogBindData.newsType" :disabled="newTypeStatus" placeholder="请选择" size="small">
              <el-option :value="0" label="文字" />
              <el-option :value="1" label="图文" />
              <el-option :value="2" label="视频" />
            </el-select>
          </el-form-item>
          <el-form-item label="标题" prop="newsTitle">
            <el-input v-model="dialogBindData.newsTitle" :disabled="disableIinput" size="small" type="text" placeholder="请输入资讯标题"/>
          </el-form-item>
          <!--          <el-form-item label="排序" prop="sort">
          <el-input v-model="dialogBindData.sort" size="small" type="text" placeholder="" maxlength="2" />
          </el-form-item> -->
          <el-form-item v-if="dialogBindData.newsType === 1" label="资讯封面图" prop="otherUrl" class="three">
            <zxfmt
              v-if="isInit"
              :img-logo-url="dialogBindData.otherUrl"
              :status="dialogType"
              :new-type="dialogBindData.newsType"
              @editSuccess="imgData"
              @deleteSuccess="deleteIconData" />
          </el-form-item>
          <el-form-item v-if="dialogBindData.newsType === 2" label="视频封面图" prop="fristFrameUrl" class="three">
            <zxfmt
              v-if="isInit"
              :img-logo-url="dialogBindData.fristFrameUrl"
              :status="dialogType"
              :new-type="dialogBindData.newsType"
              @editSuccess="imgData"
              @deleteSuccess="deleteVideoImg" />
          </el-form-item>
          <el-form-item v-if="dialogBindData.newsType === 2" label="视频" prop="" class="three">
            <video-cover v-if="isInit" :video-url="dialogBindData.otherUrl" :status="dialogType" @videoSuccess="videoData" />
          </el-form-item>
          <!--          <el-form-item label="分类" prop="typeId">
          <el-select v-model="dialogBindData.typeId" :disabled="disableIinput" placeholder="请选择" size="small">
          <el-option v-for="(item,index) in videoTypeData" :key="index" :label="item.name" :value="item.id" />
          </el-select>
          </el-form-item> -->
          <el-form-item label="资讯内容" prop="newsContent" class="three">
            <!-- <Tinymce v-if="isInit" v-model="dialogBindData.newsContent" /> -->
            <el-input v-if="isInit" v-model="dialogBindData.newsContent" :autosize="{ minRows: 8, maxRows: 12}" :disabled="disableIinput" type="textarea"/>
          </el-form-item>
          <div class="btns-wrapper">
            <el-button size="small" @click="handleClose">取 消</el-button>
            <el-button :loading="buttonState" :disabled="disableIinput" type="primary" size="small" @click="submmitFun">保 存</el-button>
          </div>
        </div>
      </el-form>
    </el-dialog>

    <el-dialog v-if="isTopInit" :visible.sync="topDialogState" :before-close="tophandleClose" title="置顶" top="5vh" width="40%">
      <el-form ref="dialogBindData" :model="dialogBindData" :rules="rules" label-width="30%" status-icon class="demo-ruleForm">
        <div class="formBody">
          <el-form-item label="置顶" prop="topDays">
            <el-input
              v-model="dialogBindData.topDays"
              size="small"
              placeholder="请输入"
              style="width:auto;float:left"
              @keyup.native="proving($event)" />
            <div style="float: left;padding:0 15px;">天</div>
          </el-form-item>
          <div class="btns-wrapper">
            <el-button size="small" @click="tophandleClose">取 消</el-button>
            <el-button :loading="buttonState" type="primary" size="small" @click="topSubmmitFun">保 存</el-button>
          </div>
        </div>
      </el-form>
    </el-dialog>

    <el-dialog :visible.sync="syncDialogState" :before-close="synchandleClose" title="" top="5vh" width="80%">
      <el-row>
        <el-col :span="10">
          <div class="el-table-header">可选商户</div>
          <div class="el-table-search" style="text-align: center;">
            <el-form ref="dialogBindData" :inline="true" :model="dialogBindData" label-position="right" status-icon class="demo-form-inline">
              <el-form-item label="" prop="catId">
                <el-select v-model="dialogBindData.searchTypeOne" :disabled="disableIinput" placeholder="请选择分类" size="small">
                  <el-option :value="0" label="商户名称" />
                  <el-option :value="1" label="商家ID" />
                  <el-option :value="2" label="所在区域" />
                </el-select>
              </el-form-item>
              <el-form-item label="">
                <el-input v-model="dialogBindData.syncTitleOne" size="small" type="text" placeholder="" />
              </el-form-item>
              <el-form-item>
                <el-button type="primary" size="small" @click="searchSyncOne">查 询</el-button>
              </el-form-item>
            </el-form>
          </div>
          <el-table ref="selection" :data="syncVideoData" border style="width: 100%" @selection-change="checkAll">
            <el-table-column type="selection" width="50" />
            <el-table-column prop="sellerId" label="商家ID" />
            <el-table-column prop="sellerName" label="商家名称" />
            <el-table-column prop="addrStreet" label="所属区域" />
          </el-table>
        </el-col>
        <el-col :span="4">
          <div class="opSetting">
            <div @click="handelSelect">
              <el-button :size="buttonSize" icon="el-icon-d-arrow-right" type="primary">
                选中
              </el-button>
            </div>
            <!-- 						<div class="spacing" @click="handleRemoveSelect">
							<el-button icon="el-icon-d-arrow-left" :disabled="nowSelectRightData.length?false:true" :size="buttonSize" type="primary">
								取消
							</el-button>
						</div> -->
          </div>
        </el-col>

        <el-col :span="10">
          <div class="el-table-header">已选商户</div>
          <div class="el-table-search" style="text-align: center;">
            <el-form ref="dialogBindData" :inline="true" :model="dialogBindData" label-position="right" status-icon class="demo-form-inline">
              <el-form-item label="" prop="catId">
                <el-select v-model="dialogBindData.searchTypeTwo" :disabled="disableIinput" placeholder="请选择分类" size="small">
                  <el-option :value="0" label="商户名称" />
                  <el-option :value="1" label="商家ID" />
                  <el-option :value="2" label="所在区域" />
                </el-select>
              </el-form-item>
              <el-form-item label="">
                <el-input v-model="dialogBindData.syncTitleTwo" size="small" type="text" placeholder="" />
              </el-form-item>
              <el-form-item>
                <el-button type="primary" size="small" @click="searchSyncTwo">查 询</el-button>
              </el-form-item>
            </el-form>
          </div>
          <el-table :data="syncRightData" border style="width: 100%">
            <!-- 						<el-table-column type="selection" width="30"></el-table-column> -->
            <el-table-column prop="sellerId" label="商家ID" />
            <el-table-column prop="sellerName" label="商家名称" />
            <el-table-column prop="addrStreet" label="所属区域" />
            <el-table-column align="center" label="操作">
              <template slot-scope="scope">
                <el-button type="primary" size="mini" plain @click="delSync(scope.row)">删除</el-button>
              </template>
            </el-table-column>
          </el-table>
        </el-col>
      </el-row>
      <el-row>
        <div class="btns-wrapper">
          <el-button size="small" @click="synchandleClose">取 消</el-button>
          <el-button :loading="buttonState" type="primary" size="small" @click="syncSubmmitFun">保 存</el-button>
        </div>
      </el-row>
    </el-dialog>
  </div>
</template>
<script>
import * as information from '../../api/information.js'
import zxfmt from '../../views/information/component/commodity_img'
import videoCover from '../../views/information/component/videoupload'
import { validateNumber } from '../../utils/validate'
import { getUserInformation } from '@/utils/auth'
export default {
  components: {
    zxfmt,
    videoCover
  },

  filters: {

  },
  data() {
    const onlyNumber = (rule, value, callback) => {
      if (!validateNumber(value)) {
        callback(new Error('请输入数字'))
      } else {
        callback()
      }
    }

    return {
      isInit: true,
      isTopInit: true,
      // 输入禁用
      disableIinput: false,
      // 页面搜索
      seacherParam: {
        newsContent: '',
        newsType: '',
        nickName: ''
      },
      searchShow: false,
      // 列表数据
      dataOption: null,
      pageNo: 1,
      pageSize: 10,
      rowCount: null, // 总条数
      // 视频分类数据
      videoTypeData: '',
      type: '',
      dialogState: false,
      topDialogState: false,
      syncDialogState: false,
      editorData: null,
      dialogType: 1, // 1--增加  2--编辑  3--查看
      newTypeStatus: false,
      // 对话框表单数据对象
      dialogBindData: {
        newsType: 0,
        id: '',
        nickName: '',
        newsTitle: '',
        sort: '',
        fristFrameUrl: '',
        newsContent: '',
        otherUrl: '',
        newOtherUrl: '',
        searchTypeOne: 0,
        syncTitleOne: '',
        searchTypeTwo: 0,
        syncTitleTwo: '',
        topDays: 0
      },
      rules: {
        newsContent: [{
          required: true,
          message: '请输入资讯内容',
          trigger: 'blur'
        }],
        topDays: [{
          required: true,
          validator: onlyNumber,
          message: '请输入置顶天数'
        }]
      },
      // 按钮状态
      buttonState: false,
      delBtn: true,
      delIdArr: [],
      buttonSize: 'large',
      syncVideoData: [],
      nowSelectData: [],
      nowSelectRightData: [],
      syncRightData: [],
      photoGallery: []
    }
  },
  computed: {
    // 计算属性返回对话框文本
    dialogTitle() {
      if (this.dialogType === 1) {
        return '新增资讯'
      }
      if (this.dialogType === 2) {
        return '修改资讯'
      } else {
        return '查看资讯'
      }
    }
  },
  beforeMount() {
    // 	  this.type = this.$route.params.type // 类型
    // 	  this.editorData = this.$route.params.data // 编辑数据

    this.getList()
  },
  methods: {
    formatImageUrl(value) {
      if (value !== '' || value !== null) {
        console.log("value.join(',')[0]", value.split(',')[0])
        return value.split(',')[0]
      }
    },

    // 获取用户信息
    getUser() {
      return JSON.parse(getUserInformation())
    },

    proving(e) {
      var keynum = window.event ? e.keyCode : e.which
      // var keychar = String.fromCharCode(keynum)
      if (keynum === 189 || keynum === 190 || keynum === 110 || keynum === 109 || keynum === 96) {
        e.target.value = ''
      }
    },

    // 反显
    reBindData(data) {
      const arr = []
      for (const key in this.dialogBindData) {
        console.log('key', key)
        if (key === 'otherUrl' && data[key]) {
          arr.push(...data[key].split(','))
        } else {
          this.dialogBindData[key] = data[key]
        }
      }

      this.dialogBindData['otherUrl'] = arr
      console.log('arr', arr)
    },
    // 重置
    resetFun() {
      this.$refs.seacherParam.resetFields()
      this.getList()
    },
    // 删除
    changeFun(data) {
      this.datavalID = data
    },
    handleSizeChange(val) {
      console.log(`每页 ${val} 条`)
      this.pageSize = val
      this.getList()
    },
    handleCurrentChange(val) {
      console.log(`当前页: ${val}`)
      this.pageNo = val
      this.getList()
    },
    handleClose() {
      for (const key in this.dialogBindData) {
        if (key === 'sellerType') {
          this.dialogBindData[key] = 1
        } else if (key === 'settlementPeriod') {
          this.dialogBindData[key] = 1
        } else {
          this.dialogBindData[key] = ''
        }
      }
      this.dialogState = false
      this.disabled = false
      this.disableIinput = false
      this.isInit = false
      this.newTypeStatus = false
      // this.$refs.dialogBindData.clearValidate()
    },
    tophandleClose() {
      this.topDialogState = false
      this.isTopInit = false
    },
    seachFun() {
      const param = {
        current: 1,
        size: this.pageSize,
        newsContent: this.seacherParam.newsContent,
        newsType: this.seacherParam.newsType,
        nickName: this.seacherParam.nickName
      }
      information.getNewsSearch(param).then(res => {
        if (res.data.code !== 1) {
          this.$message.error(res.data.msg)
          return false
        }
        if (res.data.data === 'null' || res.data.data === null) {
          return false
        }
        // 初始话表格数据
        this.dataOption = res.data.data.records
        // 初始化分页数据
        this.rowCount = res.data.data.total
        this.pageSize = res.data.data.size
      })
    },
    // 查询列表数据
    getList() {
      const param = {
        current: this.pageNo,
        size: this.pageSize,
      }
      information.shareNews(param).then(res => {
        console.log('查询资讯列表响应', res)
        if (res.data.code !== 1) {
          this.$message.error(res.data.msg)
          return false
        }
        if (res.data.data === 'null' || res.data.data === null) {
          return false
        }
        // 初始话表格数据
        this.dataOption = res.data.data.records
        // 初始化分页数据
        this.rowCount = res.data.data.total
        this.pageSize = res.data.data.size
      })
    },
    // 查看
    check(data) {
      this.$router.push({
        name: '/v1/comment1',
        params: {
          type: 3,
          id: data.id
        }
      })
    },

    // 添加
    add() {
      this.dialogType = 1
      this.dialogState = true
      this.isInit = true
      this.getVideoType()
      this.dialogBindData.newsType = 0
    },

    look(data) {
      this.newTypeStatus = true
      this.disableIinput = true
      this.dialogType = 3
      this.dialogState = true
      this.disabled = true
      this.isInit = true
      this.getVideoType()
      this.reBindData(data)
      this.dialogBindData.id = data.id
      this.dialogBindData.newsType = data.newsType
    },

    // 编辑
    edit(data) {
      this.newTypeStatus = true
      console.log('newsType：', data.newsType)
      this.dialogType = 2
      this.dialogState = true
      this.disabled = true
      this.isInit = true
      this.getVideoType()
      this.reBindData(data)
      this.dialogBindData.id = data.id
      this.dialogBindData.newsType = data.newsType
    },
    // 查询视频分类
    getVideoType() {
      const param = {
        current: this.pageNo,
        size: this.pageSize
      }
      information.getVideoTypeNow(param).then(res => {
        console.log('查询到的资讯分类数据：', res)
        if (res.data.code !== 1) {
          this.$message.error(res.data.msg)
          return false
        }
        if (res.data.data === 'null' || res.data.data === null) {
          return false
        }
        // 初始话表格数据
        this.videoTypeData = res.data.data.records
      })
    },
    // 删除
    del(data) {
      if (data === 0) {
        if (this.datavalID.length === 0) {
          this.$message({
            type: 'warning',
            message: '请选择商家!'
          })
        }
        return false
      }
      this.$confirm('确认要删除资讯吗,是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.delDataTable(data)
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消'
        })
      })
    },
    delDataTable(data) {
      const ids = []
      ids.push(data.id)
      information.deleteNews(ids).then(res => {
        if (res.data.code === 1) {
          this.$message({
            type: 'success',
            message: '删除成功!'
          })
          this.getList()
        }
      })
    },
    top(data) {
      this.dialogBindData.topDays = ''
      this.dialogBindData.id = data.id
      if (data.isTop === 0) {
        this.topDialogState = true
        this.isTopInit = true
      } else {
        this.$confirm('确认要取消置顶吗,是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          this.unTopDataTable(data)
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消'
          })
        })
      }
    },
    unTopDataTable(data) {
      const param = {
        id: this.dialogBindData.id,
        isTop: 0
      }
      information.unTopNews(param).then(res => {
        if (res.data.code !== 1) {
          this.$message({
            message: res.data.msg,
            type: 'warning'
          })
          this.buttonState = false
          return false
        }
        this.$message({
          message: '取消置顶成功',
          type: 'success'
        })
        this.buttonState = false
        this.getList()
        this.tophandleClose()
      })
    },
    publish(data) {
      if (data === 0) {
        if (this.datavalID.length === 0) {
          this.$message({
            type: 'warning',
            message: '请选择商家!'
          })
        }
        return false
      }
      let str
      if (data.newsStatus === 2) {
        str = '确认要发布吗,是否继续?'
      } else {
        str = '确认要下线吗,是否继续?'
      }
      this.$confirm(str, '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.publishDataTable(data)
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消'
        })
      })
    },

    publishDataTable(data) {
      const param = {
        id: data.id,
        newsStatus: data.newsStatus === 1 ? 2 : 1
      }

      information.news(param).then(res => {
        if (res.data.code !== 1) {
          this.$message({
            message: res.data.msg,
            type: 'warning'
          })
          this.buttonState = false
          return false
        }
        this.$message({
          message: '操作成功',
          type: 'success'
        })
        this.buttonState = false
        this.getList()
        this.handleClose()
      })
    },

    // 提交
    submmitFun() {
      const param = {
        newsTitle: this.dialogBindData.newsTitle,
        newsContent: this.dialogBindData.newsContent,
        newsType: this.dialogBindData.newsType,
        nickName: this.dialogBindData.nickName
      }

      // 			if (this.dialogBindData.otherUrl instanceof Array && this.dialogBindData.otherUrl.length > 0) {
      // 			  this.dialogBindData.newOtherUrl = this.dialogBindData.otherUrl.join(',')
      // 			}
      //
      // 			this.dialogBindData.otherUrl = this.dialogBindData.newOtherUrl

      if (this.dialogBindData.newsType === 1) {
        console.log('-----提交图文资讯信息------')
        console.log('this.dialogBindData.otherUrl', this.dialogBindData.otherUrl)
        param.otherUrl = this.dialogBindData.otherUrl
      } else if (this.dialogBindData.newsType === 2) {
        param.fristFrameUrl = this.dialogBindData.fristFrameUrl
        param.otherUrl = this.dialogBindData.otherUrl
        if (param.otherUrl instanceof Array && param.otherUrl.length > 0) {
          param.otherUrl = param.otherUrl.join(',')
        }
      }

      if (this.dialogType !== 1) {
        param.id = this.dialogBindData.id
      }

      this.$refs.dialogBindData.validate((valid) => {
        if (valid) {
          if (this.dialogBindData.newsType === 2 && this.dialogBindData.fristFrameUrl === '') {
            this.$message({
              message: '请上传视频封面图',
              type: 'warning'
            })
            return false
          }
          if (this.dialogType === 1) {
            information.addNews(param).then(res => {
              if (res.data.code !== 1) {
                this.$message({
                  message: res.data.msg,
                  type: 'warning'
                })
                this.buttonState = false
                return false
              }
              this.$message({
                message: '添加成功',
                type: 'success'
              })
              this.buttonState = false
              this.getList()
              this.handleClose()
            })
          } else {
            information.updateNews(param).then(res => {
              if (res.data.code !== 1) {
                this.$message({
                  message: res.data.msg,
                  type: 'warning'
                })
                this.buttonState = false
                return false
              }
              this.$message({
                message: '编辑成功',
                type: 'success'
              })
              this.buttonState = false
              this.getList()
              this.handleClose()
            })
          }
        } else {
          return false
        }
      })
    },

    // 置顶
    topSubmmitFun() {
      const param = {
        id: this.dialogBindData.id,
        isTop: 1,
        topDays: this.dialogBindData.topDays
      }

      this.$refs.dialogBindData.validate((valid) => {
        if (valid) {
          information.topNews(param).then(res => {
            if (res.data.code !== 1) {
              this.$message({
                message: res.data.msg,
                type: 'warning'
              })
              this.buttonState = false
              return false
            }
            this.$message({
              message: '置顶成功',
              type: 'success'
            })
            this.buttonState = false
            this.getList()
            this.tophandleClose()
          })
        } else {
          return false
        }
      })
    },

    imgData(data) {
      if (this.dialogBindData.newsType === 1) {
        let newData = ''
        for (let i = 0; i < data.length; i++) {
          if (i === data.length - 1) {
            newData += data[i].url
          } else {
            newData += data[i].url + ','
          }
        }
        this.dialogBindData.otherUrl = newData
        console.log('当前的otherUrl', this.dialogBindData.otherUrl)
      } else if (this.dialogBindData.newsType === 2) {
        this.dialogBindData.fristFrameUrl = data
      }
    },
    videoData(data) {
      this.dialogBindData.otherUrl = data
    },

    deleteIconData(data) {
      console.log('deleteIconData', data)
      this.photoGallery = data
      console.log('this.photoGallery', this.photoGallery)
      console.log('otherUrl', this.dialogBindData.otherUrl)
      if (this.photoGallery.length > 0) {
        const arr = []
        for (let i = 0; i < this.photoGallery.length; i++) {
          arr.push(this.photoGallery[i].url)
        }

        this.dialogBindData.otherUrl = arr.join(',')
      }
    },

    deleteVideoImg(data) {
      this.photoGallery = data
      if (this.photoGallery.length > 0) {
        const arr = []
        for (let i = 0; i < this.photoGallery.length; i++) {
          arr.push(this.photoGallery[i].url)
        }
        this.dialogBindData.fristFrameUrl = arr.join(',')
      } else {
        this.dialogBindData.fristFrameUrl = ''
      }
    },

    sync(data) {
      this.syncDialogState = true
      this.dialogBindData.id = data.id
      this.getSync()
      this.getSyncTwo()
    },
    getSync() {
      const param = {
        id: this.dialogBindData.id,
        sellerId: '',
        sellerName: '',
        addrStreet: ''
      }
      information.selectSellerDifferenceSet(param).then(res => {
        console.log('查询同步资讯的响应', res)
        if (res.data.code !== 1) {
          this.$message.error(res.data.msg)
          return false
        }
        if (res.data.data === 'null' || res.data.data === null) {
          return false
        }
        // 初始化分页数据
        this.syncVideoData = res.data.data
      })
    },
    getSyncTwo() {
      const param = {
        id: this.dialogBindData.id,
        sellerId: '',
        sellerName: '',
        addrStreet: ''
      }
      information.selectSellerIntersection(param).then(res => {
        console.log('查询同步资讯的响应1', res)
        if (res.data.code !== 1) {
          this.$message.error(res.data.msg)
          return false
        }
        if (res.data.data === 'null' || res.data.data === null) {
          return false
        }
        // 初始化分页数据
        this.nowSelectData = res.data.data
        this.syncRightData = res.data.data
      })
    },
    synchandleClose() {
      this.syncDialogState = false
    },
    checkAll(val) {
      console.log('change value', val)
      this.nowSelectData = val
    },
    checkRightAll(val) {
    },
    // 选中
    handelSelect() {
      this.syncRightData = this.syncRightData.concat(this.nowSelectData)
      console.log('右边列表数据', this.syncRightData)
      // 计算差集
      const difference = this.syncVideoData.concat(this.nowSelectData).filter(v => this.syncVideoData.includes(v) && !this.nowSelectData.includes(v))
      this.syncVideoData = difference
      console.log('左边同步列表数据', this.syncVideoData)
    },
    // 取消
    handleRemoveSelect() {
      this.data1 = this.handleConcatArr(this.syncVideoData, this.nowSelectRightData)
      this.handleRemoveTabList(this.nowSelectRightData, this.selectArr)
      this.nowSelectRightData = []
    },
    // 同步
    syncSubmmitFun() {
      const memberIds = []
      console.log('同步数据：', this.syncRightData)
      for (const i in this.syncRightData) {
        memberIds.push(this.syncRightData[i].memberId)
      }
      const param = { newsId: this.dialogBindData.id, memberIds: memberIds }
      information.addSyncNews(param).then(res => {
        if (res.data.code !== 1) {
          this.$message({
            message: res.data.msg,
            type: 'warning'
          })
          this.buttonState = false
          return false
        }
        this.$message({
          message: '保存成功',
          type: 'success'
        })
        this.buttonState = false
        this.getSync()
        this.getSyncTwo()
        this.syncDialogState = false
      })
    },
    delSync(data) {
      if (data === 0) {
        if (this.datavalID.length === 0) {
          this.$message({
            type: 'warning',
            message: '请选择商家!'
          })
        }
        return false
      }
      this.$confirm('确认要删除吗,是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.deleteSync(data)
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消'
        })
      })
    },

    deleteSync(data) {
      const ids = []
      ids.push(data.id)
      information.deleteSyncNews(ids).then(res => {
        if (res.data.code === 1) {
          this.$message({
            type: 'success',
            message: '删除成功!'
          })
          this.getSync()
          this.getSyncTwo()
        }
      })
    },

    // 可选商家查询
    searchSyncOne() {
      const param = { id: this.dialogBindData.id }
      if (this.dialogBindData.searchTypeOne === 0) {
        param.sellerName = this.dialogBindData.syncTitleOne
        param.sellerId = ''
        param.addrStreet = ''
      } else if (this.dialogBindData.searchTypeOne === 1) {
        param.sellerId = this.dialogBindData.syncTitleOne
        param.sellerName = ''
        param.addrStreet = ''
      } else {
        param.addrStreet = this.dialogBindData.syncTitleOne
        param.sellerId = ''
        param.sellerName = ''
      }
      information.selectSellerDifferenceSet(param).then(res => {
        console.log('搜索同步视频的响应', res)
        if (res.data.code !== 1) {
          this.$message.error(res.data.msg)
          return false
        }
        if (res.data.data === 'null' || res.data.data === null) {
          return false
        }
        // 初始化分页数据
        this.syncVideoData = res.data.data
        console.log('syncVideoData', this.syncVideoData)
      })
    },

    // 未选商家查询
    searchSyncTwo() {
      const param = {
        id: this.dialogBindData.id
      }
      if (this.dialogBindData.searchTypeTwo === 0) {
        param.seller_name = this.dialogBindData.syncTitleTwo
        param.sellerId = ''
        param.addrStreet = ''
      } else if (this.dialogBindData.searchTypeTwo === 1) {
        param.sellerId = this.dialogBindData.syncTitleTwo
        param.sellerName = ''
        param.addrStreet = ''
      } else {
        param.addrStreet = this.dialogBindData.syncTitleTwo
        param.sellerId = ''
        param.sellerName = ''
      }
      information.selectSellerIntersection(param).then(res => {
        console.log('搜索同步视频的响应', res)
        if (res.data.code !== 1) {
          this.$message.error(res.data.msg)
          return false
        }
        if (res.data.data === 'null' || res.data.data === null) {
          return false
        }
        // 初始化分页数据
        this.syncRightData = res.data.data
      })
    },
    newsTypeFun(data) {
      if (data === 0) {
        return '文字'
      } else if (data === 1) {
        return '图文'
      } else if (data === 2) {
        return '视频'
      }
    }
  }
}
</script>
<style type="text/scss" lang="scss" scoped="scoped">
	.comment {
		cursor: pointer;
		color: #409EFF
	}
	.opSetting {
		text-align: center;
		margin-top:30px;
	}
	.spacing {
		margin-top:10px;
	}
	.el-table-header {
			text-align: center;
			padding:14px 0;
			font-size: 18px;
	}
</style>
